package rad.framework.mda.generator.template.main.java.seam;

import java.util.*;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class ControllerBean
{
  protected static String nl;
  public static synchronized ControllerBean create(String lineSeparator)
  {
    nl = lineSeparator;
    ControllerBean result = new ControllerBean();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = "/*" + NL + " * ============================================================================" + NL + " *                   GNU Lesser General Public License" + NL + " * ============================================================================" + NL + " */" + NL + "package ";
  protected final String TEXT_3 = ";" + NL;
  protected final String TEXT_4 = NL;
  protected final String TEXT_5 = NL + NL + "/**" + NL + " * ";
  protected final String TEXT_6 = NL + " *" + NL + " * @author ";
  protected final String TEXT_7 = NL + " * @version 1.0" + NL + " * @generated" + NL + " */" + NL + "@Name(\"";
  protected final String TEXT_8 = "Controller\")" + NL + "@Stateful" + NL + "//@Clustered" + NL + "//@RolesAllowed(\"User\")" + NL + "//@SecurityDomain(\"rad-framework\")" + NL + "//@Scope(ScopeType.SESSION)" + NL + "// TODO add @Begin and @End annotations to transitions" + NL + "public class ";
  protected final String TEXT_9 = "ControllerBean extends AbstractControllerBean implements ";
  protected final String TEXT_10 = "Controller {" + NL + "    /** @generated */" + NL + "    private static final long serialVersionUID = 1L;";
  protected final String TEXT_11 = NL + NL + "    /** @generated */" + NL + "    @In(required=false)" + NL + "    private ";
  protected final String TEXT_12 = " ";
  protected final String TEXT_13 = ";";
  protected final String TEXT_14 = NL + NL + "    /**" + NL + "     * ";
  protected final String TEXT_15 = NL + "     * @NOT generated " + NL + "     */" + NL + "    public String ";
  protected final String TEXT_16 = "() {" + NL + "       //TODO implement";
  protected final String TEXT_17 = NL + "       if (true) {" + NL + "          return \"";
  protected final String TEXT_18 = "\";" + NL + "       }";
  protected final String TEXT_19 = NL + "       return \"";
  protected final String TEXT_20 = "\";";
  protected final String TEXT_21 = NL + "    }" + NL + "" + NL + "    /** @generated */" + NL + "    public boolean is";
  protected final String TEXT_22 = "Rendered() {" + NL + "       return true;" + NL + "    }" + NL + "" + NL + "    /** @generated */" + NL + "    public boolean is";
  protected final String TEXT_23 = "Disabled() {" + NL + "       return false;" + NL + "    }";
  protected final String TEXT_24 = NL + "}";
  protected final String TEXT_25 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    Region region = (Region) argument;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(region.getStateMachine()));
    stringBuffer.append(TEXT_3);
    ImportManager importManager = ImportHelper.makeImportManager("");
    ImportHelper.addImport(region);
    importManager.addImport("javax.annotation.security.RolesAllowed");
    importManager.addImport("javax.ejb.Stateful");
    importManager.addImport("org.jboss.annotation.ejb.Clustered");
    importManager.addImport("org.jboss.annotation.security.SecurityDomain");
    importManager.addImport("org.jboss.seam.annotations.End");
    importManager.addImport("org.jboss.seam.annotations.In");
    importManager.addImport("org.jboss.seam.annotations.Name");
    importManager.addImport("org.jboss.seam.ScopeType");
    importManager.addImport("org.jboss.seam.annotations.Scope");
    stringBuffer.append(TEXT_4);
    importManager.addImport("org.jboss.seam.annotations.Factory");
    importManager.addImport("rad.framework.seam.AbstractControllerBean");
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_5);
    stringBuffer.append(TypeHelper.getDocumentation(region));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(NameHelper.getUncapName(region));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(NameHelper.getCapName(region));
    stringBuffer.append(TEXT_9);
    stringBuffer.append(NameHelper.getCapName(region));
    stringBuffer.append(TEXT_10);
    for (Iterator<org.eclipse.uml2.uml.Class> j=JsfHelper.getPageDomains(region); j.hasNext();) { org.eclipse.uml2.uml.Class uml2Class = (org.eclipse.uml2.uml.Class)j.next();
    stringBuffer.append(TEXT_11);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.uncapSafeName(uml2Class));
    stringBuffer.append(TEXT_13);
    }
    for (Iterator<State> j=JsfHelper.getPages(region); j.hasNext();) { State state = (State)j.next();
    for (Iterator<Transition> k=state.getOutgoings().iterator(); k.hasNext();) { Transition t = (Transition)k.next();
    stringBuffer.append(TEXT_14);
    stringBuffer.append(TypeHelper.getDocumentation(t));
    stringBuffer.append(TEXT_15);
    stringBuffer.append(NameHelper.removeSpaces(NameHelper.uncapSafeName(t.getSource()) + NameHelper.getCapName(t)));
    stringBuffer.append(TEXT_16);
    if (t.getTarget() instanceof Pseudostate && ((Pseudostate)t.getTarget()).getKind().equals(PseudostateKind.CHOICE_LITERAL)) {
    for (Iterator<Transition> l=((Pseudostate)t.getTarget()).getOutgoings().iterator(); k.hasNext();) { Transition t2 = (Transition)l.next();
    stringBuffer.append(TEXT_17);
    stringBuffer.append(t2.getName());
    stringBuffer.append(TEXT_18);
    }} else {
    stringBuffer.append(TEXT_19);
    stringBuffer.append(t.getName());
    stringBuffer.append(TEXT_20);
    }
    stringBuffer.append(TEXT_21);
    stringBuffer.append(NameHelper.removeSpaces(NameHelper.getCapName(t.getSource()) + NameHelper.getCapName(t)));
    stringBuffer.append(TEXT_22);
    stringBuffer.append(NameHelper.removeSpaces(NameHelper.getCapName(t.getSource()) + NameHelper.getCapName(t)));
    stringBuffer.append(TEXT_23);
    }}
    stringBuffer.append(TEXT_24);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_25);
    return stringBuffer.toString();
  }
}
